import 'package:flutter_utils/flutter_utils.dart';
import 'package:get_storage/get_storage.dart';

class GetStorageManager {
  static GetStorageManager? _instance;
  GetStorageManager._internal();
  factory GetStorageManager() {
    return _instance ??= GetStorageManager._internal();
  }
  late GetStorage _appBox;
  Future<void> init() async {
    await GetStorage.init();
    _appBox = GetStorage();
  }

  ///可以存储 String、int、double、Map 和 List
  Future<void> save(String key, dynamic value) async {
    LogUtil.log('save key: $key, value: $value');
    await _appBox.write(key, value);
  }

  T? read<T>(String key) {
    final value = _appBox.read(key);
    LogUtil.log('read key: $key value: $value');
    return value;
  }

  T getKeys<T>() {
    return _appBox.getKeys();
  }

  T getValues<T>() {
    return _appBox.getValues();
  }

  bool hasData(String key) {
    return _appBox.hasData(key);
  }

  Future<void> remove(String key) async {
    return _appBox.remove(key);
  }
}
